package com.xingzhe.media.api;

import com.xingzhe.base.exception.XingZhePlusException;
import com.xingzhe.base.model.RestResponse;
import com.xingzhe.base.utils.StringUtil;
import com.xingzhe.media.mapper.MediaFilesMapper;
import com.xingzhe.media.model.po.MediaFiles;
import com.xingzhe.media.service.MediaFileService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(value = "媒资文件管理接口",tags = "媒资文件管理接口")
@RestController
@RequestMapping("/open")
public class MediaOpenController {
    @Resource
    MediaFilesMapper mediaFilesMapper;

    @GetMapping("/preview/{mediaId}")
    public RestResponse<String>  getPlayUrlMedia(@PathVariable(value = "mediaId")String mediaId){
        MediaFiles mediaFiles = mediaFilesMapper.selectById(mediaId);
        if (mediaFiles==null){
            return RestResponse.validfail("找不到视频~");
        }
        if (StringUtils.isEmpty(mediaFiles.getUrl())) {
            return RestResponse.success(mediaFiles.getUrl());
        }
        return RestResponse.success(mediaFiles.getUrl());
    }
}
